﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarShop.Domain.Entities;

namespace CarShop.Data.EntityFramework.Mappings
{
    internal class OrderConfiguration : EntityBaseConfiguration<Order, int>
    {
        public OrderConfiguration()
        {
            Property(o => o.Price).IsRequired();
            Property(o => o.OrderStatusId).IsRequired();

            HasMany(o => o.Cars)
                .WithOptional(c => c.Order)
                .HasForeignKey(c => c.OrderId);

            HasRequired(o => o.OrderStatus).WithMany(o => o.Orders).HasForeignKey(o => o.OrderStatusId);

            HasRequired(o => o.User).WithMany(u => u.Orders).HasForeignKey(o => o.UserId);
        }
    }
}
